<?php
require("config.php");
function getFileExt($filename){
    // 1. The "explode/end" approach
    $arr = explode('.', $filename);
    $ext = end($arr);
    
    // 2. The "strrchr" approach
    $ext = substr(strrchr($filename, '.'), 1);
    
    // 3. The "strrpos" approach
    $ext = substr($filename, strrpos($filename, '.') + 1);
    
    // 4. The "preg_replace" approach
    $ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $filename);
    
    return $ext;
}
function importJSCss($filename, $options = null){
    if(getFileExt($filename) != "js" && getFileExt($filename) != "css"){
        echo "<!-- " . $filename . " is not js or css .file -->";
        return;
    }
    if(file_exists($filename)){
        $att = "";
        if($options != null){
            foreach($options as $key => $value){
                $att = $att . $key . "=\"" . $value . "\" "; 
            }
        }
        if(getFileExt($filename) == "js")
            return sprintf("<script type=\"text/javascript\" src=\"%s\" %s></script>",LQ_ROOT . "/". $filename, $att);
        else
            return sprintf("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" %s />",LQ_ROOT . "/" . $filename, $att);
    }
    return "<!-- Unable to load " . $filename . "-->";
}
function convertString($str)
{
    $len = strlen($str);
    if ($len > 100) {
        $str = substr($str, 0, 75) . "...";
    }
    return $str;
}
?>